<template>
  <div class="loaction_box">
    <topHeader>
      <div slot="left">
        <img src="./../../assets/img/return.png" alt="" @click="goMine">
      </div>
      <span slot="center">
        一键报警
      </span>
    </topHeader>
    <div class="location_con">
      <div class="location_adress">
        <p>当前位置：</p>
        {{ adress }}
      </div>
    </div>
    <div class="call_police">
      <p>提示：谎报警情，依法追责</p>
      <span>谎报警情将可能被处以五日以上十日以下拘留</span>
      <div class="btn" @click="goPolice">一键报警</div>
    </div>
  </div>
</template>

<script>
import topHeader from './../../components/topHeader'
import axios from 'axios'
export default {
  data () {
    return {
      adress: ''
    }
  },

  components: {
    topHeader
  },

  computed: {},

  mounted () {
    this.getPosition()
  },

  methods: {
    // 开始定位
    getPosition () {
      let self = this
      var map = new AMap.Map('container', {
        zoom: 16,
        scrollWheel: false,
        resizeEnable: true
      })
      map.plugin(['AMap.Geolocation', 'AMap.ToolBar'], function () {
        let geolocation = new AMap.Geolocation({
          enableHighAccuracy: true, // 是否使用高精度定位，默认:true
          timeout: 10000 // 超过10秒后停止定位，默认：无穷大
          // buttonOffset: new AMap.Pixel(10, 20), // 定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
          // zoomToAccuracy: true, // 定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
          // buttonPosition:'RB'
        })
        geolocation.getCurrentPosition(function (status, result) {
          if (status === 'complete') {
            console.log(result)
            axios.get(`https://restapi.amap.com/v3/geocode/regeo?key=50e36952d417ba5a2b89fd7b3886c43e&location=${result.position.lng},${result.position.lat}`).then(res => {
              console.log(res.data.regeocode.formatted_address)
              self.adress = res.data.regeocode.formatted_address
            })
          }
        })
      })
    },
    goMine () {
      this.$router.go(-1)
    },
    goPolice () {
      window.location.href = 'tel:' + '110'
    }
  }
}
</script>
<style lang='less' scoped>
@import url('./location.less');
</style>